package com.example.demo.controller;

import com.example.demo.common.PageData;
import com.example.demo.common.ResponseData;
import com.example.demo.domain.User.UserInfo;
import com.example.demo.domain.User.UserLogin;
import com.example.demo.domain.User.UserQuery;
import com.example.demo.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
public class UserController {
    @Autowired
    IUserService userService;

    /*** 注册用户* */
    @PutMapping("/registUser")  //@Valid代表对后面的对象参数进行校验
    public ResponseData<String> registUser(@RequestBody @Valid UserInfo userInfo){
        return userService.registUser(userInfo);
    }

    /*** 新增用户* */
    @PutMapping("/addUser")
    public ResponseData<String> addUser(@RequestBody UserInfo userInfo){
        return userService.addUser(userInfo);
    }

    /*** 登录用户* */
    @PostMapping("/loginUser")
    public ResponseData<String> loginUser(@RequestBody UserLogin userLogin){
        return  userService.loginUser(userLogin);
    }

    /*** 删除用户* */
    @DeleteMapping("/deleteUser")
    public ResponseData<String> deleteUser(@RequestParam("userName") String userName){
        return  userService.deleteUser(userName);
    }

    /*** 查询用户* */
    @PutMapping("/getUser")
    public ResponseData<UserInfo> getUser(@RequestParam("userName") String userName){return userService.getUser(userName);}

    /*** 修改用户* */
    @PutMapping("/modifyUser")//修改用户
    public ResponseData<Boolean> modifyUser(@RequestBody UserInfo userInfo){
        return userService.modifyUser(userInfo);
    }

    /*** 分页* */
    @PostMapping("page")
    public ResponseData<PageData<UserInfo>>page(@RequestBody UserQuery userQuery){
        return userService.page(userQuery);
    }

  /**
   * 上传文件（图片，word，pdf之类的）接口
   * */


//    @PutMapping("/page")
//    public String index(UserQuery userQuery){
//        PageInfo<User> userPageInfo= userServiceTwo.listUserByName(userQuery);
//        return null;
//    }
}
